/*******************************************************************************
 * Copyright 2007, 2009 InnovaSoft SA http://www.innovasoft.biz/
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
 
package biz.innovasoft.nodb;


/**
 * 
 * This class allows to configure the repositories. Each repository has its own configuration.
 * 
 * @author Diego Miranda
 *
 */
public class RepositoryConfiguration {

	public final static long DEFAULT_JOURNAL_AGE = 180000;
	public final static long DEFAULT_JOURNAL_SIZE = 50000000;
	
	public final static long DEFAULT_TIME_TO_LIVE = 30;
	public final static long DEFAULT_IDLE_TIME = 30;
	
	public final static int DEFAULT_SNAPSHOT_TIME = 60; // Minutes
	
	private String repositoryPath;
	private RepositoryType type = RepositoryType.MULTI_THREADED;
	private boolean prevaylerTransactionFiltering = false;
	private long journalFileAge = DEFAULT_JOURNAL_AGE;
	private long journalFileSize = DEFAULT_JOURNAL_SIZE;
	private boolean reindexAtStartup = true;
	private boolean _transient = false;
	private boolean useTemporalIndex = true;
	private long temporalTimeToLive = DEFAULT_TIME_TO_LIVE;
	private long temporalIdleTime = DEFAULT_IDLE_TIME;
	private boolean nonPrevalentQueries = true;
	private boolean automaticSnapshots = false;
	private long automaticSnapshotsTime = DEFAULT_SNAPSHOT_TIME;

	public RepositoryConfiguration () {}
	
	/**
	 * @return true, if the repository is transient.
	 */
	public boolean isTransient() {
		return _transient;
	}

	/**
	 * Sets this repository in transient.
	 * 
	 * @param transientt
	 */
	public void setTransient(boolean transientt) {
		this._transient = transientt;
	}

	/**
	 * Tells if the repository is compressed.
	 * 
	 * @return true if the repository is COMPRESSEd.
	 */
	public boolean isCompressed() {
		return (type == RepositoryType.COMPRESSED);
	}

	/**
	 * Tells if this repository should be indexed once it is loaded in memory.
	 * 
	 * @return true, if should be indexed.
	 */
	public boolean isReindexAtStartup() {
		return reindexAtStartup;
	}

	/**
	 * Indicates that this repository should be indexed at startup.
	 * 
	 * @param reindexAtStartup
	 */
	public void setReindexAtStartup(boolean reindexAtStartup) {
		this.reindexAtStartup = reindexAtStartup;
	}
	
	/**
	 * Returns the type of the repository. There are three types of modes:
	 * 
	 * SINGLE_THREADED
	 * MULTI_THREADED
	 * COMPRESSED
	 * 
	 * @return the repository type.
	 */
	public RepositoryType getRepositoryType() {
		return type;
	}

	/**
	 * Sets the repository type.
	 * 
	 * @param type
	 */
	public void setRepositoryType(RepositoryType type) {
		this.type = type;
	}

	/**
	 * Returns the journal file age. This is a prevayler configuration.
	 * 
	 * @return the journal age.
	 */
	public long getJournalFileAge() {
		return journalFileAge;
	}

	/**
	 * Sets the age of the Prevayler journal file in milliseconds.
	 */
	public void setJournalFileAge(long journalFileAge) {
		this.journalFileAge = journalFileAge;
	}

	/**
	 * Returns the journal file size. 
	 */
	public long getJournalFileSize() {
		return journalFileSize;
	}

	/**
	 *	Sets the journal file size in bytes. 
	 */
	public void setJournalFileSize(long journalFileSize) {
		this.journalFileSize = journalFileSize;
	}

	/**
	 *	Return the path of this repository. 
	 */
	public String getRepositoryPath() {
		return repositoryPath;
	}

	/**
	 *	Sets the path of this repository. 
	 */
	public void setRepositoryPath(String repositoryPath) {
		this.repositoryPath = repositoryPath;
	}

	public boolean isPrevaylerTransactionFiltering() {
		return prevaylerTransactionFiltering;
	}

	public void setPrevaylerTransactionFiltering(
			boolean prevaylerTransactionFiltering) {
		this.prevaylerTransactionFiltering = prevaylerTransactionFiltering;
	}

	/**
	 * Returns true if the repository will create a temporal index. A temporal index is useful
	 * when you executes a query over objects that are not indexed. By default, a repository
	 * use temporal indexes. 
	 */
	public boolean getUseTemporalIndex() {
		return useTemporalIndex;
	}

	/**
	 *	Configures the use of temporal indexes. 
	 */
	public void setUseTemporalIndex(boolean useTemporalIndex) {
		this.useTemporalIndex = useTemporalIndex;
	}

	/**
	 *	Return the time to live (in seconds) of the temporal indexes. 
	 */
	public long getTemporalTimeToLive() {
		return temporalTimeToLive;
	}

	/**
	 *	Sets the time to live (in seconds) of the temporal indexes. 
	 */
	public void setTemporalTimeToLive(long temporalTimeToLive) {
		this.temporalTimeToLive = temporalTimeToLive;
	}

	/**
	 *	Return the time in seconds a temporal index will remain inactive. 
	 */
	public long getTemporalIdleTime() {
		return temporalIdleTime;
	}

	/**
	 *	Sets the time an index will remain inactive before its deletion. 
	 */
	public void setTemporalIdleTime(long temporalIdleTime) {
		this.temporalIdleTime = temporalIdleTime;
	}
	
	public boolean getUseNonPrevalentQueries () {
		return this.nonPrevalentQueries;
	}
	
	public void setUseNonPrevalentQueries (boolean nonPrevalentQueries) {
		this.nonPrevalentQueries = nonPrevalentQueries;
	}
	
	/**
	 * @return true if the RepositoryManager should take automatic snapshots.
	 */
	public boolean isAutomaticSnapshots() {
		return automaticSnapshots;
	}

	/**
	 * Tells the manager to take automatic snapshots.
	 * 
	 * @param automaticSnapshots true, if the manager should take automatic snapshots.
	 */
	public void setAutomaticSnapshots(boolean automaticSnapshots) {
		this.automaticSnapshots = automaticSnapshots;
	}

	/**
	 * Returns the time interval, in minutes, between every automatic snapshot.
	 * 
	 * @return the time interval between the automatic snapshots.
	 * 
	 */
	public long getAutomaticSnapshotsTime() {
		return automaticSnapshotsTime;
	}

	/**
	 * Sets the time interval, in minutes, between the automatic snapshots.
	 * 
	 * @param automaticSnapshotsTime
	 */
	public void setAutomaticSnapshotsTime(long automaticSnapshotsTime) {
		this.automaticSnapshotsTime = automaticSnapshotsTime;
	}
}
